home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / quartz / quartz10.lha / include / synch.h < prev    next >
C/C++ Source or Header  |  1990-04-29  |  2KB  |  77 lines

  1. /* Synchronization data structures and routines, available publicly */
  2.  
  3. #include "asm.h"
  4.  
  5. /* Condition variables are always protected by spin or blocking locks */
  6. typedef struct condition {
  7.     unsigned int type;
  8.     Thread *waiting;
  9.     struct synch_profile *p;
  10.     } Condition;
  11.  
  12. typedef Condition SpinCondition;
  13.  
  14. typedef struct lock {
  15.     unsigned int type;
  16.     int lock;
  17.     SpinLock slock; 
  18.     Thread *waiting;
  19.     struct synch_profile *p;
  20.     } Lock;
  21.  
  22. /* Potentially fuzzy-barriers
  23.  * and all those that check in do not have to wait (ie, their threads can die)
  24.  * (but all that wait must check in)
  25.  */
  26.  
  27. typedef struct barrier {
  28.     unsigned int type;
  29.     SpinLock l;
  30.     int initial;
  31.     int count;
  32.     int iteration;
  33.     SpinCondition c;
  34.     } Barrier;
  35.  
  36. typedef Barrier SpinBarrier;
  37.  
  38. /* Exported */
  39.  
  40. void SpinLockInit(), SpinLockDispose();
  41.  
  42. #ifdef PROFILE
  43. void SpinLockAcquire(), SpinLockRelease(), SpinLockRelBlock();
  44. #else
  45. #define SpinLockAcquire(s)     MY_LOCK(s)
  46. #define SpinLockRelease(s)  MY_UNLOCK(s)
  47. #endif
  48.  
  49. #define SLNPInit(s)        ((s)->l = 0)
  50. #define SLNPAcquire(s)    MY_LOCK(s)
  51. #define SLNPRelease(s)    MY_UNLOCK(s)
  52. #define SLNPTestAndGet(s)    MY_CLOCK(s)
  53. #define SpinLockTestAndGet(s)    MY_CLOCK(s)
  54.  
  55. void LockInit(), LockAcquire(), LockRelease(), LockDispose();
  56.  
  57. void ConditionInit(), ConditionSignal(), ConditionWait(), ConditionDispose();
  58. #define ConditionWaitLock(c,l)      (ConditionWait(c,l), LockAcquire(l))
  59.  
  60. void SpinConditionWait();
  61.  
  62. #define SpinConditionInit(c,n)        ConditionInit((Condition *)c,n)
  63. #define SpinConditionSignal(c)        ConditionSignal((Condition *)c)
  64. #define SpinConditionBroadcast(c)    ConditionBroadcast((Condition *)c)
  65. #define SpinConditionDispose(c)        ConditionDispose((Condition *)c)
  66. #define SpinConditionWaitLock(c,l)  (SpinConditionWait(c,l), SpinLockAcquire(l))
  67.  
  68. void SpinBarrierInit(), SpinBarrierWait(), BarrierInit(), BarrierWait();
  69. int BarrierCheckIn();
  70.  
  71. #define SpinBarrierCheckIn(b)        BarrierCheckIn((Barrier *)b)
  72. #define SpinBarrierHit(b)            SpinBarrierWait(b, SpinBarrierCheckIn(b))
  73. #define SpinBarrierDispose(b)        BarrierDispose((Barrier *)b)
  74.  
  75. #define BarrierHit(b)                BarrierWait(b, BarrierCheckIn(b))
  76.  
  77.